package com.zzyl.nursing.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.zzyl.nursing.dto.DeviceDto;
import com.zzyl.nursing.vo.DeviceDataVo;
import com.zzyl.nursing.vo.DeviceDetailVo;
import com.zzyl.nursing.vo.ProductVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.zzyl.common.annotation.Log;
import com.zzyl.common.core.controller.BaseController;
import com.zzyl.common.core.domain.AjaxResult;
import com.zzyl.common.enums.BusinessType;
import com.zzyl.nursing.domain.Device;
import com.zzyl.nursing.service.IDeviceService;
import com.zzyl.common.utils.poi.ExcelUtil;
import com.zzyl.common.core.page.TableDataInfo;

/**
 * 设备管理Controller
 * 
 * @author xjl
 * @date 2025-10-17
 */
@RestController
@RequestMapping("/nursing/device")
@Api(tags = "设备管理的接口")
public class DeviceController extends BaseController
{
    @Autowired
    private IDeviceService deviceService;

    /**
     * 查询设备管理列表
     */
    @ApiOperation("查询设备管理列表")
    @PreAuthorize("@ss.hasPermi('nursing:device:list')")
    @GetMapping("/list")
    public TableDataInfo list(Device device)
    {
        startPage();
        List<Device> list = deviceService.selectDeviceList(device);
        return getDataTable(list);
    }

    /**
     * 同步设备管理
     */
    @ApiOperation("同步设备管理")
    @PreAuthorize("@ss.hasPermi('nursing:device:list')")
    @PostMapping("/syncProductList")
    public AjaxResult syncProductList()
    {
       deviceService.syncProductList();
        return AjaxResult.success();
    }

    /**
     * 同步设备管理
     */
    @ApiOperation("1.3 注册设备")
    @PreAuthorize("@ss.hasPermi('nursing:device:list')")
    @PostMapping ("/register")
    public AjaxResult register(@RequestBody DeviceDto dto)
    {
       deviceService.register(dto);
        return AjaxResult.success();
    }


    /**
     * 同步设备管理
     */
    @ApiOperation("同步设备管理")
    @PreAuthorize("@ss.hasPermi('nursing:device:list')")
    @GetMapping("/allProduct")
    public AjaxResult allProduct()
    {
        List<ProductVo> list =deviceService.allProduct();
        return AjaxResult.success(list);
    }

    /**
     * 查看设备详情
     */
    @ApiOperation("查看设备详情")
    @PreAuthorize("@ss.hasPermi('nursing:device:list')")
    @GetMapping("/{iotId}")
    public AjaxResult deviceDetail(@PathVariable("iotId") String iotId)
    {
         DeviceDetailVo deviceDetail =deviceService.deviceDetail(iotId);
        return AjaxResult.success(deviceDetail);
    }

    /**
     * 查看设备数据
     */
    @ApiOperation("查看设备数据")
    @PreAuthorize("@ss.hasPermi('nursing:device:list')")
    @GetMapping("queryServiceProperties/{iotId}")
    public AjaxResult queryProduct(@PathVariable("iotId") String iotId)
    {
        List<DeviceDataVo> dataVo =deviceService.queryProduct(iotId);
        return AjaxResult.success(dataVo);
    }

    /**
     * 修改设备数据*/

    @ApiOperation("修改设备数据")
    @PreAuthorize("@ss.hasPermi('nursing:device:list')")
    @PutMapping
    public AjaxResult updateDevice(@RequestBody DeviceDto dto)
    {
        deviceService.updateDevice(dto);
        return AjaxResult.success();
    }

    /**
     * 删除设备数据*/

    @ApiOperation("删除设备数据")
    @PreAuthorize("@ss.hasPermi('nursing:device:list')")
    @DeleteMapping("/{iotId}")
    public AjaxResult deleteDevice(@PathVariable("iotId") String iotId)
    {
        deviceService.deleteDevice(iotId);
        return AjaxResult.success();
    }



    //nursing/device/queryProduct/68f1e7b7ef46cd424ce4cf46

    @ApiOperation("获取服务产品")
    @PreAuthorize("@ss.hasPermi('nursing:device:list')")
    @GetMapping("/queryProduct/{productKey}")
    public AjaxResult queryProductKey(@PathVariable("productKey") String productKey)
    {
        return   deviceService.queryProductKey(productKey);

    }

}
